package top.jle.spring.basic.fis;


import top.jle.spring.basic.fis.matchers.MatchGetter;
import top.jle.spring.basic.fis.matchers.MatchRunner;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;

public interface MatcherExecutor {
    static MatchRunner matchAndRun(boolean express){
        return (r,others) -> {
            if(express){
                r.run();
            }else if(others!=null && others.length>0){
               others[0].run();
            }
        };
    }
    static MatchRunner matchAndRun(BooleanSupplier express){
        return matchAndRun(Boolean.TRUE.equals(express.getAsBoolean()));
    }

    static <T> MatchGetter<T> matchAndGet(boolean express){
        return (s, others)->{
            if(express){
               return s.get();
            }else if(others!=null && others.length>0){
               return others[0].get();
            }
            return null;
        };
    }

}
